<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">


    <body>

        <ui:composition template="./../../Template/generalTemplate.xhtml">



            <ui:define name="content">
                <h:form id="form1" prependId="false">
                    <f:view beforePhase="#{manageSalesOrderManagedBean.initView}">
                        <div style="height:495px;overflow:auto;">
                            <p:panel header="Sales Order Information" style="margin-top:10px; margin-left:10px;">
                                <div style="height:160px; width:1200px;">   
                                    <h:panelGrid style="margin-top:10px;position:relative;border:cadetblue solid 1px;width:300px;height:150px;float:left" columns="2" cellpadding="2">
                                        <h:outputText value="Sales Order ID;"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.id}"/>
                                        <h:outputText value ="Created Date:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.dateCreated}">
                                            <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                        </h:outputText>
                                        <h:outputText value ="Processed By:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.employeeName}"/>
                                        <h:outputText value="Last Modified on:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.dateLastModified}">
                                            <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                        </h:outputText>
                                    </h:panelGrid>
                                    <h:panelGrid style="margin-left:50px;margin-top:10px;position:relative;border:cadetblue solid 1px;width:300px;height:150px;float:left" columns="2" cellpadding="2"> 
                                        <h:outputText value="Customer Name:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.customer.name}"/>
                                        <h:outputText value="Customer Contact Person:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.customer.contactPersonName}"/>
                                        <h:outputText value="Customer Address:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.customer.address.streetName}"/>
                                        <h:outputText value="Address City:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.customer.address.city}"/>
                                    </h:panelGrid>
                                    <h:panelGrid style="margin-left:50px;margin-top:10px; position:relative;border:cadetblue solid 1px;width:300px;height:150px;float:left" columns="2" cellpadding="2"> 
                                        <h:outputText value="Sales Order Status"/>
                                        <h:outputText style="color:blue;" value="#{manageSalesOrderManagedBean.statusMessage}"/>
                                        <h:outputText value="Payment Mode:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.paymentMode}"/>
                                        <h:outputText value="Total Amount:"/>
                                        <h:outputText value="#{manageSalesOrderManagedBean.salesOrder.totalAmount}"/>  
                                    </h:panelGrid>
                                </div>
                                <h:outputText style="margin-top:20px; color: cadetblue; font-size:18px;" value="Line Item List"/> 
                                <p:dataTable style="margin-top:10px;" value="#{manageSalesOrderManagedBean.salesOrder.salesOrderLineItems}" var="l" dynamic="true" > 
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Proudct" />
                                        </f:facet>
                                        <h:outputText value="#{l.product.productName}" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Quantity" />
                                        </f:facet>
                                        <h:outputText value="#{l.quantity}" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Original Unit Price" />
                                        </f:facet>
                                        <h:outputText value="#{l.product.basePrice}" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Promotional Price" />
                                        </f:facet>
                                        <h:outputText value="#{l.product.promotionPrice}" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Discount" />
                                        </f:facet>
                                        <h:outputText value="#{l.discount}" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Unit Price" />
                                        </f:facet>
                                        <h:outputText value="#{l.price}" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Subtotal" />
                                        </f:facet>
                                        <h:outputText value="#{l.cumAmount}" />
                                    </p:column>  
                                </p:dataTable>
                                <p:fieldset legend="Delivery Order Info" toggleable="true" toggleSpeed="500"  
                                            toggleListener="#{manageSalesOrderManagedBean.handleToggle}"  
                                            onToggleUpdate="deliveryInfo" collapsed="true">  

                                    <p:dataTable style ="margin-top:10px;" value ="#{manageSalesOrderManagedBean.salesOrder.childDeliveryOrders}" var="o">
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="DeliveryOder #" />
                                            </f:facet>
                                            <h:outputText value="#{o.id}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Line Item"/>
                                            </f:facet>
                                            <p:commandLink value="Show" immediate="true" update="dldataTable" onclick="dlg2.show()">
                                                <f:setPropertyActionListener value="#{o}" target="#{manageSalesOrderManagedBean.selectedDeliveryOrder}"/>
                                            </p:commandLink>
                                            
                                        </p:column>    
                                        <p:column>
                                            <f:facet name="header">Delivery Date</f:facet>
                                            <h:outputText value="#{o.deliveryDate}">
                                                <f:convertDateTime pattern ="dd/MM/yyyy"/>
                                            </h:outputText>    
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Delivery Location</f:facet>
                                            <h:outputText value="#{o.shippingAddress.streetName},"/>
                                            <h:outputText value="#{o.shippingAddress.city}"/>
                                        </p:column> 
                                    </p:dataTable> 

                                </p:fieldset> 
                            </p:panel>
                            <p:commandButton style="margin-top:10px; margin-left:10px;" value="Confirm SalesOrder" onclick="confirmation.show()"/><br/>
                            <p:commandButton style="margin-top:10px; margin-left:10px;" value="View All Sales Order" action="#{manageSalesOrderManagedBean.viewAll}"/>
                            <p:commandButton style="margin-left:800px;position: relative;" value="Amend Order" action="#{manageSalesOrderManagedBean.amendOrder}"/>
                             
                            
                            <p:messages id="message"/>
                            <p:confirmDialog message="Are you sure to Confirm Sales Order?"  
                                             showEffect="bounce" hideEffect="explode"  
                                             header="Sales Order Confrimation" severity="alert" widgetVar="confirmation">  

                                <p:commandButton value="Yes Sure" update="form1" ajax="true" oncomplete="confirmation.hide()"  
                                                 action="#{manageSalesOrderManagedBean.confirmSalesOrder}" />  
                                <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   

                            </p:confirmDialog>
                        </div>
                    </f:view>   
                </h:form>    
                <h:form prependId="false">
                
                <p:dialog header="DelvieryOrder LineItemList" widgetVar="dlg2" resizable="true" width="500">  
                    <p:dataTable id="dldataTable" value="#{manageSalesOrderManagedBean.selectedDeliveryOrder.deliveryOrderLineItems}" var="lineItem">
                        <p:column>
                            <f:facet name="header">Product</f:facet>
                            #{lineItem.product.productName}
                        </p:column>  
                        <p:column>
                            <f:facet name="header">Quantity</f:facet>
                            #{lineItem.quantity}
                        </p:column>  
                        <p:column>
                            <f:facet name="header">Unit Price</f:facet>
                            #{lineItem.price}
                        </p:column>  
                        <p:column>
                            <f:facet name="header">Total Price</f:facet>
                            #{lineItem.cumAmount}
                        </p:column>  

                    </p:dataTable>   
                </p:dialog>  
                
                </h:form>    
                
            </ui:define>

        </ui:composition>

    </body>
</html>
